package com.bcxj.internalcommon.dto;

import com.bcxj.internalcommon.constant.CommonStatusEnum;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * ClassName: ResponseResult
 * Package: com.bcxj.internalcommon.dto
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/9/15 21:52
 * @Version 1.0
 * @Since 1.0
 */
@Accessors(chain = true)
@Data
@NoArgsConstructor
public class ResponseResult<T> {
    private Integer code;
    private String message;
    private T data;

    /**
     * 成功
     * @param data
     * @return
     * @param <T>
     */
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<T>().setCode(CommonStatusEnum.SUCESS.getCode()).setMessage(CommonStatusEnum.SUCESS.getMessage()).setData(data);
    }

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<T>().setCode(CommonStatusEnum.SUCESS.getCode()).setMessage(CommonStatusEnum.SUCESS.getMessage());
    }


    /**
     * 失败
     * @param data
     * @return
     * @param <T>
     */
    public static <T> ResponseResult<T> fail(T data) {
        return new ResponseResult<T>().setCode(CommonStatusEnum.FAIL.getCode()).setMessage(CommonStatusEnum.FAIL.getMessage()).setData(data);
    }


    public static <T> ResponseResult<T> fail(Integer code, String message, T data) {
        return new ResponseResult<T>().setCode(code).setMessage(message).setData(data);
    }

    public static <T> ResponseResult<T> fail(Integer code, String message) {
        return new ResponseResult<T>().setCode(code).setMessage(message);
    }


    public static <T> ResponseResult<T> fail(CommonStatusEnum commonStatusEnum) {
        return new ResponseResult<T>().setCode(commonStatusEnum.getCode()).setMessage(commonStatusEnum.getMessage());
    }
}
